#include "DbStorage/RemovePackageStorageCmd.hpp"
#include "Model/Package.hpp"
#include "CaseDB/Connection.hpp"
#include "CaseDB/Statement.hpp"
#include "CaseDB/RecordSet.hpp"
#include "Model/Package.hpp"
#include "Model/Project.hpp"
#include <cassert>

namespace DbStorage
{

RemovePackageStorageCmd::RemovePackageStorageCmd( Model::Package& subject, CaseDB::Connection& dbConnection )
	: DbStorageCmd( subject, Storage::StorageCommand::Delete, dbConnection)
{
}

// ---------------------------------------------------------------------------------------------------------------------

void RemovePackageStorageCmd::execute()
{
	using namespace CaseDB;

	Model::Package& package = dynamic_cast< Model::Package&>( rSubject_);
	assert( NULL != package.project());


	Statement dbStatement( "{call DELETE_PACKAGE( ?, ?)}");
	dbStatement.addParameter( DbTypesEnum::Integer, package.storedID());
	dbStatement.addParameter( DbTypesEnum::Integer, package.project()->storedID());

	dbConnection_.execute( dbStatement);
}


} // namespace DbStorage

